package com.yunhe.control;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.swing.RepaintManager;

import com.yunhe.bean.Orders;
import com.yunhe.bean.ShopPingJia;
import com.yunhe.bean.ShopUser;
import com.yunhe.service.pingjiaService;

/**
 * Servlet implementation class pingjia
 */
@WebServlet("/qian/PingJia.do")
public class PingJia extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PingJia() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub	
		int uid=(int) request.getSession().getAttribute("userid");
		String pcontext=request.getParameter("pingjia");		
		int sid=Integer.parseInt(request.getSession().getAttribute("sid").toString());
		ShopUser user=new ShopUser();
		Orders od=new Orders();
		
		if(user.getUid()==od.getUid()){
		ShopPingJia addping=new ShopPingJia();	
		addping.setSid(sid);
		addping.setUid(uid);
		addping.setPcontext(pcontext);
		int x=new pingjiaService().addpingJia(addping);
		if(x>0){
			request.getRequestDispatcher("index.jsp").forward(request, response);
			
		}else{			
			request.getRequestDispatcher("index.jsp").forward(request, response);
			
		}
		}else{
			
		  PrintWriter writer = response.getWriter();
		  writer.print("没有过买过该商品，不能评价");			
		}
		
		
		
	}

}
